/*
 * Copyright (C) 2008, Velocityme Partnership
 * SprintBean.java
 *
 * Created on 26 Aug 2008, 20:43
 */

package com.velocityme.entity;

import javax.ejb.*;
import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;
import com.velocityme.interfaces.*;

/**
 *
 * @author  Robert Crida
 * @ejb.bean
 *           type="CMP"
 *           cmp-version="2.x"
 *           name="Sprint"
 *           jndi-name="ejb/Sprint"
 *           view-type="local"
 * @ejb.transaction type="Required"
 *
 * @ejb.value-object match="*"
 *
 * @ejb.persistence table-name="sprint"
 *
 * @ejb.util generate="physical"
 *
 * @ejb.finder signature="java.util.Collection findByDate(java.util.Date date)"
 *              query="SELECT OBJECT(o) FROM Sprint o WHERE o.startDate < ?1 AND o.stopDate > ?1"
 *
 * @ejb.finder signature="java.util.Collection findByPersonDate(com.velocityme.interfaces.PersonLocal personLocal, java.util.Date date)"
 *              query="SELECT OBJECT(o) FROM Sprint o, IN (o.teamPersonsLocal) p WHERE o.startDate < ?2 AND o.stopDate > ?2 AND (o.scrumMasterLocal = ?1 OR p = ?1)"
 *
 * @jboss.persistence create-table="true"
 *                    remove-table="false"
 */
public abstract class SprintBean implements EntityBean {
    
    /**
    * Context set by container
    */
    protected javax.ejb.EntityContext m_entityContext;
   
    public void setEntityContext(javax.ejb.EntityContext entityContext) {
        m_entityContext = entityContext;
    }

    public void unsetEntityContext() {
        m_entityContext = null;
    }

    /** @ejb.create-method */
    public com.velocityme.interfaces.SprintPK ejbCreate(com.velocityme.interfaces.NodeLocal p_nodeLocal,
                                                        com.velocityme.valueobjects.SprintValue p_value,
                                                        java.util.Collection p_personsLocal) throws CreateException {
        setSprintId(p_nodeLocal.getNodeId());
        // EJB 2.0 spec says return null for CMP ejbCreate methods.
        return null;
    }

    public void ejbPostCreate(com.velocityme.interfaces.NodeLocal p_nodeLocal,
                              com.velocityme.valueobjects.SprintValue p_value,
                              java.util.Collection p_personsLocal) throws CreateException {
        // CMR relations must be set in ejbPostCreate
        setSprintValue(p_value);
        setNodeLocal(p_nodeLocal);
        setTeamPersonsLocal(p_personsLocal);
    }

    /**
     *  This gets a local object from a remote object.
     *  @ejb.interface-method view-type="remote"
     */
    public com.velocityme.interfaces.SprintLocal getLocal() {
        return (SprintLocal)m_entityContext.getEJBLocalObject();
    }
    
    /** @ejb.interface-method view-type="both" */
    public abstract com.velocityme.valueobjects.SprintValue getSprintValue();
    /** @ejb.interface-method view-type="local" */
    public abstract void setSprintValue(com.velocityme.valueobjects.SprintValue sprintValue);
    
    //=======================================================================
    //
    //                   ATTRIBUTES
    //
    //=======================================================================
      
    /**
     * @ejb.persistence column-name="sprintId"
     * @ejb.interface-method view-type="local"
     * @ejb.pk-field
     */
    public abstract java.lang.Integer getSprintId();
    /** @ejb.interface-method view-type="local" */
    public abstract void setSprintId(java.lang.Integer sprintId);

    /**
     * @ejb.persistence column-name="startDate"
     * @ejb.interface-method view-type="local"
     */
    public abstract java.util.Date getStartDate();
    /** @ejb.interface-method view-type="local" */
    public abstract void setStartDate(java.util.Date startDate);

    /**
     * @ejb.persistence column-name="stopDate"
     * @ejb.interface-method view-type="local"
     */
    public abstract java.util.Date getStopDate();
    /** @ejb.interface-method view-type="local" */
    public abstract void setStopDate(java.util.Date stopDate);

    //=======================================================================
    //
    //                   RELATIONSHIPS
    //
    //=======================================================================
    
    /**
     * @ejb.interface-method view-type="local"
     * @ejb.relation name="Sprint-Node"
     *               role-name="Sprint-has-a-Node"
     * @jboss.relation fk-column="nodeIdFk"
     *                 related-pk-field="nodeId"
     * @ejb.value-object match="*" 
     *                   aggregate="com.velocityme.valueobjects.NodeValue"
     *                   aggregate-name="NodeValue"
     */
    public abstract com.velocityme.interfaces.NodeLocal getNodeLocal();
    /** @ejb.interface-method view-type="local" */
    public abstract void setNodeLocal(com.velocityme.interfaces.NodeLocal nodeLocal);
    
    /**
     * @ejb.interface-method view-type="local"
     * @ejb.relation name="Sprint-ScrumMaster"
     *               role-name="Sprint-has-a-ScrumMaster"
     *               target-ejb="Person"
     *               target-role-name="ScrumMaster-has-a-Sprint"
     *               target-multiple="yes"
     * @jboss.relation fk-column="scrumMasterPersonIdFk"
     *                 related-pk-field="personId"
     * @ejb.value-object match="*" 
     *                   aggregate="com.velocityme.valueobjects.PersonValue"
     *                   aggregate-name="ScrumMasterValue"
     */
    public abstract com.velocityme.interfaces.PersonLocal getScrumMasterLocal();
    /** @ejb.interface-method view-type="local" */
    public abstract void setScrumMasterLocal(com.velocityme.interfaces.PersonLocal scrumMasterLocal);
    
    /**
     * @ejb.interface-method view-type="local"
     * @ejb.relation name="Sprint-Team"
     *               role-name="Sprint-may-have-many-TeamPersons"
     * @jboss.relation fk-column="sprintId"
     *                 related-pk-field="personId"
     * @jboss.relation-table table-name="sprintteam"
     *                       create-table="true"
     *                       remove-table="false"
     */
    public abstract java.util.Collection getTeamPersonsLocal();
    /** @ejb.interface-method view-type="local" */
    public abstract void setTeamPersonsLocal(java.util.Collection teamPersons);
    
    //=======================================================================
    //
    //                   MANAGEMENT METHODS
    //
    //=======================================================================
    
}
